package me.gacl.beetl.web.view;

import org.beetl.ext.servlet.ServletGroupTemplate;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by gacl on 2017/8/16.
 */
@WebServlet(name = "IndexServlet",value = "/index")
public class IndexServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        //模板直接访问users
        req.setAttribute("users", getMockerUsers());
        ServletGroupTemplate.instance().render("/WEB-INF/views/index.html", req, resp);
    }

    private Map getMockerUsers() {
        Map<String,Object> map = new HashMap<>();
        map.put("id", 1);
        map.put("name", "曹操");
        map.put("description", "一名枭雄");
        return map;
    }
}
